Fix file descriptor leak on /dev/urandom each time nginx reloads #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Each time nginx was reloaded (via the HUP signal), it was opening new handles to /dev/urandom for each worker process, but failing to close the old unused ones. So if you had 4 worker processes, after 3 reloads, you'd have 16 total handles to /dev/urandom open with 12 of those being unused. This led to an indefinite leaking of file descriptors on the nginx master process, which could eventually culminate in "too many files open" errors killing nginx if you managed to reload nginx enough times to hit your system file descriptor limit.
This shifts the /dev/urandom opening from the init_module into the init_process callback so that each worker process opens its own files. This then allows us to properly close those file descriptors each time a worker exits on reload via the exit_process callback.
I'm not exactly sure how to test this within the context of Test::Nginx, but in some manual testing, this does seem to fix the file descriptor leak across repeated reloads.